package proiect.fis.UI.comboBoxModel;

import java.util.Collections;
import java.util.List;
import java.util.Vector;
import javax.swing.DefaultComboBoxModel;
import proiect.fis.commons.beans.Oras;
import proiect.fis.persistence.OrasDao;

/**
 *
 * @author Boogie
 */
public class OrasModel extends DefaultComboBoxModel<Oras> {

    public static OrasDao oDao;
    private static Vector<Oras> vOrase;
    public OrasModel(Oras[] items) {
        super(items);
    }

    public OrasModel(Vector<Oras> v) {
        super(v);
    }
    
    public static OrasModel createModel(){
        List<Oras> orase = oDao.loadAll();
        if(vOrase == null){
            vOrase = new Vector<>(orase);
        }        
        if(orase.size()>vOrase.size()){
            for (Oras oras : orase) {
                if(!vOrase.contains(oras)){
                    vOrase.add(oras);
                }
            }
        }
        if(orase.size()<vOrase.size()){
            for(Oras o : vOrase){
                if(!orase.contains(o)){
                    vOrase.remove(o);
                }
            }
        }
        
        OrasModel o = new OrasModel(vOrase);
        return o;
    }
}
